package com.gexin.common.job;

import com.gexin.common.AppGlobal;
import com.gexin.model.config.Advertising;
import com.gexin.model.order.OrderMaster;
import com.jfinal.log.Log;

import java.util.Date;
import java.util.List;

/**
 * 广告位的定时器
 * 黎峻
 *  状态 ： 0 未上线  1 上线中  2 已下线
 */
public class AdvertisingJob implements Runnable {
	static Log log = Log.getLog(AdvertisingJob.class);
	
	public void run() {
		if(AppGlobal.dev_Mode){
			log.info("执行广告位定时器......");
		}
		StartActivity();
		EndActivity();
	}

	//检查开始活动
	public static void  StartActivity(){
		List<Advertising> list =Advertising.dao.find("select * from t_advertising where status = 0 and  DATE_FORMAT(start_time,'%Y-%m-%d %H:%i:%S') <= DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%S') ");
		for(Advertising activity:list){
			activity.setStatus(1);
			activity.update();
		}
	}

	//检查结束活动
	public static void  EndActivity(){
		List<Advertising> list =Advertising.dao.find("select * from t_advertising where status = 1 and DATE_FORMAT(end_time,'%Y-%m-%d %H:%i:%S') <= DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%S') ");
		for(Advertising activity:list){
			activity.setStatus(2);
			activity.update();
		}
	}
}
